<template>
  <div class="single-q">
    <div class="content">
      <n-thing content-indented>
        <template #header v-if="formData.title">
          <n-row class="title">
            <div class="index" v-if="props.index">{{ props.index + '.' }}</div>
            <span v-show="formData.required === '必填'" style="color: red"
              >*</span
            >
            {{ formData.title }}
          </n-row>
        </template>
        <template #description v-if="formData.remark">
          <div class="remark">
            {{ '——' + formData.remark }}
          </div>
        </template>
        <n-space vertical>
          <n-radio-group
            name="options"
            v-model:value="formData.option"
            @update:value="upO"
          >
            <n-space vertical v-for="item in formData.applys">
              <div>
                <div style="min-width: 8vw; display: inline-block">
                  <n-radio :key="item" :value="item.option">
                    {{ item.option }}
                  </n-radio>
                </div>
                <div style="min-width: 8vw; display: inline-block">
                  <span style="font-size: 4px">剩余名额: {{ item.left }}</span>
                </div>
                <span style="font-size: 4px">{{ item.other }}</span>
              </div>
            </n-space>
          </n-radio-group>
          <n-button
            text
            @click="clear"
            v-if="formData.option"
            style="color: #999; font-size: 0.4rem"
            >清除当前选择</n-button
          >
        </n-space>
      </n-thing>
    </div>
  </div>
</template>

<script setup lang="ts">
import { RadioButtonOn as FlashIcon } from '@vicons/ionicons5';
import { ref, reactive, onMounted } from 'vue';
const props = defineProps({
  index: {
    type: Number,
    default: 0,
  },
  title: {
    type: String,
    required: true,
  },
  required: {
    type: String,
    default: '非必填',
  },
  remark: {
    type: String,
    default: '',
  },
  applys: {
    type: Array,
    default: [],
  },
  option: {
    type: String,
    required: true,
    default: '',
  },
});
const formData: any = reactive({
  title: props.title,
  remark: props.remark,
  required: props.required,
  applys: props.applys,
  option: props.option,
});

const emit = defineEmits(['update:option']);
const upO = (value: string) => {
  emit('update:option', value);
};
const clear = () => {
  formData.option = '';
  emit('update:option', formData.option);
};
</script>

<style scoped lang="scss">
.single-q {
  .index {
    margin-right: 1vw;
  }
  .content {
    padding: 1vw;
  }
  .title {
    font-size: 1.25rem;
  }
  .remark {
    font-size: 1rem;
    color: #999;
  }
  .edit {
    padding: 0 2vw;
  }
}
</style>
